package com.lizhi.yun.system.stand.handler;/**
 * @program: sfrobot-html
 * @name StandPrescriptionInfoHandler
 * @description:
 * @author: lizhi
 * @create: 2020-05-15 14:14
 */

import com.lizhi.client.RestClientService;
import com.lizhi.common.yun.entity.ListResponseResult;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.base.BaseHandler;
import com.lizhi.yun.base.common.RoleOrganUtils;
import com.lizhi.yun.db.dao.UppUserDao;
import com.lizhi.yun.db.pojo.UppUserPOJO;
import com.lizhi.yun.system.stand.enums.StandServiceEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 *@program: sfrobot-html
 *@name StandPrescriptionInfoHandler
 *@description:
 *@author: lizhi
 *@create: 2020-05-15 14:14
 */
@Slf4j
@Service
public class StandPrescriptionInfoHandler extends BaseHandler {

    @Resource
    private UppUserDao uppUserDao;

    @Resource
    private RestClientService restClientService;

    /**
     *功能描述  分页查询
     * @author lizhi
     * @date 2020/5/15
     * @param map:
     * @return com.lizhi.common.base.PagerView<com.lizhi.db.pojo.StandPrescriptionInfoPOJO>
     */
    public ListResponseResult doMain(Map<String, Object> map, HttpServletRequest request){
        String userAcct = request.getHeader("userAcct");
        UppUserPOJO uppUserPOJO = uppUserDao.selectById(userAcct);
        /*判断医院*/
        map.put("hospitalIds", RoleOrganUtils.listOrganIds(uppUserPOJO.getOrganIds()));

        String result = restClientService.postStringToService(StandServiceEnum.HBSF_STAND_PRESCRIPTION_INFO.getEnName(), StandServiceEnum.HBSF_STAND_PRESCRIPTION_INFO.getEnValue(), SamJsonUtil.toJson(map));
        return SamJsonUtil.toObject(result, ListResponseResult.class);
    }

    /**
     *功能描述 根据处方id查询处方信息以及处方记录
     * @author lizhi
     * @date 2020/5/15
     * @param preId:
     * @return com.lizhi.db.pojo.StandPrescriptionInfoPOJO
     */
    public ListResponseResult selectById(String preId, String hospitalId, String hospitalSystemId){
        Map<String, Object> map = new HashMap<>();
        map.put("preId", preId);
        map.put("hospitalId", hospitalId);
        map.put("hospitalSystemId", hospitalSystemId);
        String result = restClientService.postStringToService(StandServiceEnum.HBSF_STAND_PRESCRIPTION_INFOS.getEnName(), StandServiceEnum.HBSF_STAND_PRESCRIPTION_INFOS.getEnValue(), SamJsonUtil.toJson(map));
        log.info("获取到的数据result:{}", result);
        return SamJsonUtil.toObject(result, ListResponseResult.class);
    }
}
